April 1996

A look at reusable components

By Daniel Bill

In the latest release of Developer/2000, version 1.2, Oracle introduced a new program-ming concept called reusable components--a collection of sub-programs that can be integrated into an application. Reusable components are Oracle's answer to reducing the time involved and the expertise required in developing certain functionality into applications. For example, let's say you want to create an About Box for your application or an Object Navigator-style interface. Oracle has assembled the items and code required to do this and packaged it as a reusable component. Version 1.2 contains a reusable component interface for Forms and Graphics, as shown in Figure A.

While reusable components in Forms and Graphics are similar in the way they provide a quick means of putting together code for an application, they function quite differently. In this article, we'll take a quick look at each. We'll also look at how reusable components can help you piece together an application more quickly, and we'll show you their benefits and limitations.

The Forms Reusable Component Library--a quick tour

When you load the Forms Reusable Component Library, you'll see a Component Navigator similar to the Object Navigator found in all Developer/2000 products. You can double-click on the Developer/2000 Forms Components item to expand it and view the available components, as shown in Figure B. In the version we're using, only a limited number of components are available. Oracle has promised to provide more components in future versions.

Using the Forms Reusable Component Library interface is really quite simple. Once you've selected a component from the Component Navigator, all you need to do is click the How To… button to reveal a set of step-by-step instructions. They explain how to incorporate the component into your Forms application, as shown in Figure C. Some of the components have demos associated with them that you can see by clicking the Demo button. That's all the Forms Component interface does.

The nuts and bolts of making components work are all the form items, property classes, procedures, and libraries that you need to add. If you've selected the Tabbed Dialog Box Control component, the instructions will tell you to drag and drop an object group from D2K_TAB.FMB to your form. This will bring over all the canvases, items, and triggers the tab control requires. You'll then be instructed to attach the library D2K_TAB.PLL to your form. You'll also need to copy some icons. You'll be instructed as to which procedures to call from your triggers so that the components are visible and the appropriate canvases are shown. The Tabbed Dialog Box Control component requires that you incorporate other components as well, so you'll also see instructions on how to add those components into your form.

Does all this sound a little complicated? We agree, this technique isn't seamless and can't exactly be called plug and play, but it does beat reinventing the wheel. What you do get from reusable components are all the items you need along with the instructions to incorporate the component into an application.

In some of the Developer/2000 version 1.2 documentation, Oracle indicated that users can create their own reusable components for sharing among developers. However, we couldn't find any instructions on how to do so. We expect this information to be forthcoming in a future version.

Reusable components in Graphics

The concept of reusable components is handled quite differently by the Graphics Reusable Component Editor (the GRC Editor) and the Forms Reusable Component Library. In the GRC Editor, not only can you view several predefined components, you can also modify these components to suit your own requirements. In addition, you can completely create your own components out of Graphics displays and procedures using special PL/SQL comments. We won't cover that aspect in this article, however. For now, let's step through the GRC Editor and see how to customize a component and place it in a Forms application.

After you click on the GRC Editor icon, shown in Figure A, and log on to the database (you'll need to log on as a user who has access to the demo tables), you'll be in the GRC Editor and the Component Display window will appear, as shown in Figure D. The toolbar shown has essentially the same options as the menu. To load a component, click on the Open icon and select one of the components (an .OGD file) from the Choose a Component File (OGD) to Open dialog box, shown in Figure E.

The selected component will then load in the Component Display window shown in Figure F. In our example, we loaded the BARLABEL.OGD file. You'll notice that the chart displayed is based on Oracle's standard demo tables. You can use your own tables and change many of the other chart properties as well.

Changing properties

If you click the Prop icon, you'll see a list of properties corresponding to the loaded chart, as shown in Figure G. The properties are divided into general categories, in this case, GENCHART (general chart properties) and BARLABEL (properties pertaining to the label that appears at the top of each bar). To modify a property, click on the desired property and then enter the new property value in the Value field. For example, to change the title of the chart, select the CHARTTITLE property and then enter your title for the chart. Some properties allow you to select a valid value from a list.

Let's say the component you've selected doesn't have all the features you'd like. In particular, you'd like to add the threshold feature, a feature in which the chart's bars appear in a different color when they're greater than a specified value. You can add the threshold feature by clicking the Custom icon and adding a new set of properties to the component. Clicking the Custom icon will take you to the Custom Properties dialog box, shown in Figure H.

To add the new feature, select the THRESH property from the Available Properties list and then click the Add button to add it to the Included Properties list. Click OK, and the new properties will be added to your component. If you now return to the Property Palette, you can adjust the THRESH properties as you like, as shown in Figure I.

Adding the component to your form

We've shown how to change some of the properties of the component; now let's see how to add the graphic component to our Forms application. Let's first set up the form.

In Forms Designer, create a new block (or use one you already have) and then add a chart item to it, as shown in Figure J. Give the chart item a name--we called ours EMPSAL. Let's also add a button that we can use to display the chart. We also need to attach the OG.PLL library (this is the library that enables Forms to interface with Graphics).

Now we need to return to the GRC Editor. After adjusting the component to your liking, you can use a scripting feature to automatically create the code needed to embed the graphic into your Forms application. To do so, click the Script icon to bring up the Script Wizard, shown in Figure K.

In this dialog box, OGD Name refers to the name of the display you're working on. Chart Area refers to the name you've given your chart item in your Forms application. There are also two check boxes indicating whether the script to be created should automatically open and whether the chart item should be resized to fit the area of the display item in your form. After filling out the text boxes, click OK. The completed code now appears in the Script Editor window, ready to be pasted into your Form.

Select the code in the Script Editor and then select the Copy command from the Edit menu. Now return to the form you created and add a WHEN-BUTTON-PRESSED trigger to the button item. Paste the code from the Script Editor into the PL/SQL Editor for the trigger. Your form is ready to be compiled and run.

If all you need is simply to display a chart in your form, the GRC Editor will create all the code you need. However, if you require more functionality than this, you'll need to modify the code and even add some of your own.

Conclusion

While Oracle's new concept of reusable objects is not quite as seamless as it sounds in the marketing literature, it is a step in the right direction. In the future, we can expect more in the area of reusable objects, which will make the process of building applications a little easier.

Daniel Bill is a Project Leader working for the City of Mississauga in Ontario, Canada. He is one of Oracle's Developer/2000 Ambassadors. You can reach him at daniel.bill@city. mississauga.on.ca.


[Return to Index for Exploring Oracle Developer/2000 and Designer/2000 - April 1996]

Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.

Exploring Oracle Developer/2000 and Designer/2000 is a publication of The Cobb Group.

1-800-223-8720